<?php
// do magic stuff before we get this far...
if (isset($_GET['test_kill_session'])) {
   session_start();
   session_destroy();
} else if (isset($_GET['test_unset_lang'])) {
   session_start();
   unset($_SESSION['lang']);
}

 include "counter2.php" ?>
<?php
// standard header
pagestart();
print "<html>\n";
pagehead(_("Language function test page"));
print "\n<body>\n";
pagetop();
print "\n<h1>" . _("Language function test page") . "</h1>\n";
print "<br>Self_URL: <a href=\"$self_url\">$self_url</a>\n";
$no_parm = preg_replace("/\?.*/", "", $self_url);
print "<br>Self_URL no parm: <a href=\"$no_parm\">$no_parm</a>\n";
print "<br><a href=\"$no_parm?test_kill_session=1\">Kill session</a>\n";
print "<br><a href=\"$no_parm?test_unset_lang=1\">Unset language</a>\n";

print "<pre>";
print_r($_GET);
print "</pre>";

print "<h2>Data dump</h2>\n";

print "<p>Session id is " . session_id() . "\n";
print "<p>Current \$_SESSION[lang] is " . $_SESSION['lang'] . "\n";
print "<br>Current \$LANG is " . getenv(LANG) . "\n";
print "<br>Current \$LANGUAGE is " . getenv(LANGUAGE) . "\n";
print "<br>Language variable is " . $language . "\n";
print "<br>Default_language variable is " . $default_language . "\n";
print "<br>language_source is " . $language_source . "\n";

print "<p>";
print "Current LC_ALL is " . setlocale(LC_ALL, 0) . "\n";
print "<br>Current LC_CTYPE is " . setlocale(LC_CTYPE, 0) . "\n";
print "<br>Current LC_COLLATE is " . setlocale(LC_COLLATE, 0) . "\n";
print "<br>Current LC_MONETARY is " . setlocale(LC_MONETARY, 0) . "\n";
print "<br>Current LC_NUMERIC is " . setlocale(LC_NUMERIC, 0) . "\n";
print "<br>Current LC_MESSAGES is " . setlocale(LC_MESSAGES, 0) . "\n";

print "<p>";
print "Current textdomain is " . textdomain(NULL) . "<br>\n";
print "<p>At Home translated is " . _("At Home") . "<br>\n";
// MISTAKE: binddtextdomain CANNOT be probed!
// print "Current bindtextdomain is " . bindtextdomain($textdomain, NULL)
// . "<br>\n";
//print "Current bind_textdomain_codeset is "
//. bind_textdomain_codeset($textdomain, NULL) . "<br>\n";

print "<p>At Home translated is " . _("At Home") . "<br>\n";

print "Homedir is " . $homedir . "\n";

print "<p>All languages supported: ";
foreach (languages_supported() as $langid) {

   print "<br>" . $langid;
   print " " . language_locale($langid);
   print " " . language_name($langid);
   # Test if setlocale() can be used on the locale
   $localename = language_locale($langid);
   $result = setlocale(LC_ALL, language_locale($langid));
   print " - setlocale: $result";   
}
$langid = "Nightmare rides!";
setlocale(LC_ALL, getenv(LANGUAGE));
# dump session vars
print "<pre>";
print_r($_SESSION);
print "</pre>";

//include "langchooser.php";

print "<p>Browser languages:<br>";
print_r(parse_accept_language());

print "<br>Best language from accept_language:";
print best_language_from_accept_language();

display_chooser();
# dump session vars
print "<pre>";
print_r($_SESSION);
print "</pre>";


pagebottom();
# dump session vars
print "<pre>";
print_r($_SESSION);
print "</pre>";

print "\n</body>\n</html>";

?>
